<template>
	<view class="signature-page">
		<view class="page-title">请用户在下方使用正楷签名</view>
		<view class="signature-box">
			<jp-signature ref="signatureRef" v-model="signInfo" penSize="4"></jp-signature>
		</view>
		<view class="page-bottom">
			<view class="action-btn-group">
				<view class="action-btn1" @click="clearSignature">重写</view>
				<view class="action-btn2" @click="confirmSignature">提交</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				signInfo: ''
			}
		},
		methods: {
			// 清除签名
			clearSignature() {
				this.$refs.signatureRef.clear();
				this.signInfo = '';
			},
			// 提交签名
			confirmSignature() {
				this.$refs.signatureRef.canvasToTempFilePath({
					success: async (res) => {
						// 是否为空画板 无签名
						if (res.isEmpty) {
							this.$Toast('请先进行签名');
							return;
						}
						// 生成图片的临时路径
						let signInfo = await this.$uploadFilePromise(res.tempFilePath);
						uni.$emit('signatureComplete', signInfo);
						uni.navigateBack({
							delta: 1
						})
					}
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.page-title {
		width: 100%;
		height: 80rpx;
		line-height: 80rpx;
		text-align: center;
		font-size: 30rpx;
		color: #333333;
		background-color: #f5f5f5;
	}

	.signature-box {
		width: 700rpx;
		height: 500rpx;
		margin: 0 auto;
		border: 1px dashed #dcdcdc;
		background: #ffffff;
	}

	/* 底部操作菜单 */
	.page-bottom {
		margin-top: 50rpx;
		display: flex;
		justify-content: space-around;
		align-items: center;
		//background: #ffffff;
		border-radius: 16rpx;
		padding: 20rpx;
		box-sizing: border-box;

		.action-btn-group {
			display: flex;
			align-items: center;
			justify-content: center;
			overflow: hidden;
			flex: 1;

			.action-btn1,
			.action-btn2 {
				width: 100%;
				height: 88rpx;
				font-weight: bold;
				font-size: 30rpx;
				line-height: 88rpx;
				text-align: center;
				border-radius: 44rpx;
				border: 2rpx solid #FE4F04;
			}

			.action-btn1 {
				color: #FE4F04;
				background: #fff;
				margin-right: 10rpx;
			}

			.action-btn2 {
				color: #fff;
				background: #FE4F04;
				margin-left: 10rpx;
			}
		}
	}
</style>